﻿using _EF扩展方法.Model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

namespace _EF扩展方法
{
    class Program
    {
        static void Main(string[] args)
        {
            #region Linq分组测试
            //using (var db = new BaseContext())
            //{
            //    var data = (from person in db.Person
            //                group person by new
            //                {
            //                    person.PersonCode,
            //                    person.Name,
            //                    person.Sex
            //                }
            //           into g
            //                select new
            //                {
            //                    g.Key.PersonCode,
            //                    g.Key.Name,
            //                    Sex = g.Key.Sex == 1 ? "男" : "女",
            //                    Birthday = (DateTime?)g.Max(p => p.Birthday),
            //                    CreateDate = (DateTime?)g.Min(p => p.CreateDate)
            //                }).ToList();

            //    var d = data;
            //} 
            #endregion

            List<Person> persons = new List<Person>();
            Person p = new Person();
            p.PersonCode = "L100000";
            p.Birthday = DateTime.Now.AddYears(-26);
            p.Name = "东方月初";
            p.CreateDate = DateTime.Now;
            p.CreateBy = 1;
            p.Sex = 1;

            persons.Add(p);

            DataTable dt = JsonConvert.DeserializeObject<DataTable>(JsonConvert.SerializeObject(persons));
            SqlParameter param = new SqlParameter("@PersonTable", dt);
            //param.Value = dt;
            using (var db = new BaseContext())
            {
                var result = db.ExtendSqlMethod("Proc_InsertPersonData", CommandType.StoredProcedure, param);

            }

            Console.ReadKey();

        }
    }
}
